/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package speechprocess;

import gui.Main;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.UIManager;

/**
 *
 * @author Oanh
 */
public class ArgtgPanel extends JPanel {
    
    Main m;
    double[] tan;
    double[] argtan;
    
    public ArgtgPanel(Main m) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception e) {
        }
        this.m = m;
        tan = new double[5000];
        argtan = new double[5000];
        setBounds(150, 20, 1100, 600);
    }
    
    @Override
    public void paint(Graphics g) {
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, 1099, 599);
        g.setColor(Color.BLACK);
        g.drawRect(0, 0, 1099, 599);

        //Khung ngang
        g.drawLine(50, 50, 1050, 50);
        g.drawLine(50, 300, 1070, 300);
        g.drawLine(50, 550, 1050, 550);
        for (int i = 0; i < 1000; i++) {
            if (i % 2 == 0) {
                g.drawLine(50 + i, 175, 50 + i, 175);
                g.drawLine(50 + i, 425, 50 + i, 425);
            }
        }
        //Khung dọc
        g.drawLine(50, 30, 50, 550);
        g.drawLine(1050, 50, 1050, 550);
        for (int i = 0; i < 500; i++) {
            if (i % 2 == 0) {
                g.drawLine(250, 50 + i, 250, 50 + i);
                g.drawLine(450, 50 + i, 450, 50 + i);
                g.drawLine(650, 50 + i, 650, 50 + i);
                g.drawLine(850, 50 + i, 850, 50 + i);
            }
        }
        //Mũi tên
        g.drawLine(45, 35, 50, 30);
        g.drawLine(55, 35, 50, 30);
        g.drawLine(1065, 295, 1070, 300);
        g.drawLine(1065, 305, 1070, 300);
        //
        g.setFont(m.jButton1.getFont());
        g.drawString("rad", 60, 35);
        g.drawString("f", 1075, 290);
        g.drawString("0", 30, 300);
        g.drawString("2.50", 5, 55);
        g.drawString("1.25", 5, 180);
        g.drawString("-1.25", 5, 430);
        g.drawString("-2.50", 5, 555);
        //Chỉ số
        g.drawString("0", 50, 580);
        for (int i = 0; i < 5; i++) {
            g.drawString((i + 1) + "000", (i + 1) * 200 + 35, 580);
        }
        
        for (int f = 1; f < 5000; f++) {
            if (m.magnitudePanel.ch1) {
                g.setColor(Color.BLUE);
                myDrawLine(g, (f - 1), m.magnitudePanel.c.atan1[f - 1], f, m.magnitudePanel.c.atan1[f]);
            }
            if (m.magnitudePanel.ch2) {
                g.setColor(Color.GREEN);
                myDrawLine(g, (f - 1), m.magnitudePanel.c.atan2[f - 1], f, m.magnitudePanel.c.atan2[f]);
            }
            if (m.magnitudePanel.ch3) {
                g.setColor(Color.MAGENTA);
                myDrawLine(g, (f - 1), m.magnitudePanel.c.atan3[f - 1], f, m.magnitudePanel.c.atan3[f]);
            }
            if (m.magnitudePanel.ch1 && m.magnitudePanel.ch2 && m.magnitudePanel.ch3) {
                g.setColor(Color.RED);
                myDrawBoldLine(g, (f - 1), m.magnitudePanel.c.atan[f - 1], f, m.magnitudePanel.c.atan[f]);
            }
        }
    }
    
    public void myDrawLine(Graphics g, double x1, double y1, double x2, double y2) {
        g.drawLine(50 + (int) (x1 / 5), 300 + (int) (y1 * 100), 50 + (int) (x2 / 5), 300 + (int) (y2 * 100));
    }
    public void myDrawBoldLine(Graphics g, double x1, double y1, double x2, double y2) {
        g.drawLine(50 + (int) (x1 / 5), 300 + (int) (y1 * 100), 50 + (int) (x2 / 5), 300 + (int) (y2 * 100));
        g.drawLine(51 + (int) (x1 / 5), 300 + (int) (y1 * 100), 51 + (int) (x2 / 5), 300 + (int) (y2 * 100));
    }
    
}
